package com.grudesign.stutrip.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.grudesign.stutrip.common.ReturnInfo;
import com.grudesign.stutrip.entity.Po.UserMsgPo;
import com.grudesign.stutrip.entity.Vo.contentMsg;
import com.grudesign.stutrip.entity.Vo.uerMsgFrontVo;
import com.grudesign.stutrip.entity.Vo.userMsgVo;
import com.grudesign.stutrip.mapper.UserMsgMapper;
import com.grudesign.stutrip.service.UserMsgService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户留言表 服务实现类
 * </p>
 *
 * @author wx
 * @since 2022-05-09
 */
@Service
public class UserMsgServiceImpl extends ServiceImpl<UserMsgMapper, UserMsgPo> implements UserMsgService {


    @Resource
    private  UserMsgMapper userMsgMapper;
    @Override
    public Object queryMsg(long cur, long next, contentMsg conMsg) {
        String content = conMsg.getContent();
        if(StringUtils.hasText(content)){
            String queryCon = "%"+content+"%";
            conMsg.setContent(queryCon);
        }
        Page<userMsgVo> page = new Page<>(cur,next);
        IPage<userMsgVo> userMsgVoIPage = userMsgMapper.selectMsgs(page, conMsg);

        return new ReturnInfo("200","ok").data("msgs",userMsgVoIPage);
    }

    @Override
    public Object saveMsg(uerMsgFrontVo msgVo) {
        UserMsgPo userMsgPo = new UserMsgPo();
        BeanUtils.copyProperties(msgVo,userMsgPo);
        int insert = baseMapper.insert(userMsgPo);
        return new ReturnInfo("200","0k").data("msg",insert);
    }
}
